{
  let obj = {
    time: '2017-03-11',
    name: 'net',
    _r: 123
  }

  let minotor = new Proxy(obj, {
    get (target, key) {
      return target[key].replace('2017', '2321')
    },
    set (target, key, value) {
      if (key == 'name') {
        return target[key] = value
      } else {
        return value
      }
    },
    has (target, key) {
      if (key == 'name') {
        return target[key]
      }
      return false
    }

  })

  console.log(minotor.time)
  minotor.name = 'jiangfeidfasd'
  console.log(minotor.time = 'dfasd')
  console.log(minotor.name)
  console.log(minotor.time)

  console.log('has', 'name' in minotor, 'time' in minotor)
}

{

  function validate (target, validator) {
    return new Proxy(target, {
      _validator: validator,

      set (target, key, value, proxy) {
        if (target.hasOwnProperty(key)) {
          let va = this._validator[key]
          if (!!va(value)) {
            return Reflect.set(target, key, value, proxy)
          } else {
            throw Error(`don't set ${key} to ${value} `)
          }
        }
        throw Error(`${key} no exist!!`)
      }
    })
  }

  const personValidators = {
    name (val) {
      return typeof val === 'string'
    },
    age (val) {
      return typeof val === 'number' && val > 18
    }
  }

  class Person {
    constructor (name, age) {
      this.name = name
      this.age = age
      return validate(this, personValidators)
    }
  }


  const person = new Person('lili' , 31)

  person.name = "lili"
  person.age = 19
  console.log(person)
}
